package com.treasure.mall.biz.bo.config;

import com.treasure.mall.zbq.common.base.ApiResult;
import com.treasure.mall.zbq.common.exception.ApiException;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * <p>
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.bo.config
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/8/26 11:28 上午
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * 
 */
@Data
public class SignConfig {

    /**
     * 奖励配置
     */
    private List<SignRewardConfig> rewardConfig;

    /**
     * 关注奖励积分
     */
    private long subscribeRewardIntegral;

    public List<SignRewardConfig> getRewardConfig() {
        if (rewardConfig == null || rewardConfig.size() == 0) {
            List<SignRewardConfig> configs = new ArrayList<>();
            configs.add(new SignRewardConfig(1, 1));
            configs.add(new SignRewardConfig(2, 2));
            configs.add(new SignRewardConfig(3, 3));
            configs.add(new SignRewardConfig(4, 4));
            configs.add(new SignRewardConfig(5, 5));
            configs.add(new SignRewardConfig(6, 6));
            configs.add(new SignRewardConfig(7, 7));
            rewardConfig = configs;
        }
        return rewardConfig;
    }

    /**
     * 得到某天的配置信息
     *
     * @param day
     * @return
     */
    public SignRewardConfig getConfigByDay(int day) {
        return getRewardConfig()
                .stream()
                .filter(p -> p.getDay() == day)
                .findFirst()
                .orElseThrow(() -> new ApiException(ApiResult.error("获取签到配置信息失败")));
    }


    public SignConfig() {
        this.rewardConfig = getRewardConfig();
        this.subscribeRewardIntegral = 0L;
    }
}
